package pl.edu.pw.perg.compinfodb.ui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;

import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.ColorHighlighter;
import org.jdesktop.swingx.decorator.Highlighter;

import pl.edu.pw.perg.compinfodb.datamodel.ElementTableModel;

@SuppressWarnings("serial")
public class ColorRenderer extends DefaultTableCellRenderer implements
		TableCellRenderer {

	private Color filterColor = new Color(170, 202, 215);
	private Color newColor = new Color(215, 205, 170);
	// Color filterColor = new Color(0x5C, 0xC5, 0xC4);
	// Color newColor = new Color(0x5E, 0xC5, 0x5C);
	
	public ColorRenderer() {
		setOpaque(true); // MUST do this for background to show up.
	}

	@SuppressWarnings("unchecked")
	public Component getTableCellRendererComponent(JTable table, Object obj,
			boolean isSelected, boolean hasFocus, int row, int column) {
		Component cell = super.getTableCellRendererComponent(table, obj,
				isSelected, hasFocus, row, column);
		
		if (table instanceof JXTable) {
			JXTable jxtable = (JXTable) table;
			row = jxtable.convertRowIndexToModel(row);
			
			
		}
		TableModel model = table.getModel();
//		if(!isSelected && row != 2)
//			cell.setBackground(Color.WHITE);
//		else if(isSelected && row != 2)
//			cell.setBackground(Color.RED);
//	
//		if(isSelected)
//			cell.setBackground(Color.RED);

//		if (row == 0 && !isSelected) {
//			cell.setBackground(filterColor);
//		}
//
//		if (model.isCellEditable(row, column))
//			cell.setBackground(filterColor);
//		// else if(!((FilterableTableModel<ITableData>) table.getModel()).
//		// isRowPersistent(row))
//		// cell.setBackground(newColor);
//		else if (!isSelected)
//			cell.setBackground(new Color(255, 255, 255));
		// cell.setBackground(filterColor);
//		if (model instanceof ElementTableModel) {
//			ElementTableModel etm = (ElementTableModel) model;
//			if (etm.getMarkedRowId() == row)
//		if(row == 2 ){
//			cell.setBackground(filterColor);
//		}
//		else
//				cell.setBackground(Color.GREEN);
//				cell.setForeground(filterColor);
//		}
//		else if(!isSelected)
//			cell.setBackground(Color.GRAY);
//		}
//		else cell.setBackground(Color.WHITE);
		return cell;
	}
}
